package com.taotao.job.schedule;

import com.taotao.job.core.enums.RelyFeature;
import com.taotao.job.core.trigger.Trigger;

import java.util.concurrent.*;

/**
 * 逻辑调度器，负责任务间依赖关系及工作流任务的调度触发
 *
 *
 * @author fanbeibei
 * @date 2021/2/24 22:25
 */
public class JobLogicScheduler {
    private ExecutorService logicScheduleThreads = new ThreadPoolExecutor(10, 40,
            30, TimeUnit.MINUTES, new ArrayBlockingQueue<>(20000));


    private Trigger trigger;

    public JobLogicScheduler(Trigger trigger) {
        this.trigger = trigger;
    }

    public void doLogicSchedule(JobSchelueInfo jobSchelueInfo) {


        logicScheduleThreads.submit(new Runnable() {
            @Override
            public void run() {

                if (!RelyFeature.mayHasPre(jobSchelueInfo.getRelyFeature())) {
                    //没有前置任务直接触发

                    triggerJob(jobSchelueInfo);
                    return;
                }

                //判断前置任务是否执行完成


            }


        });
    }




    private void triggerJob(JobSchelueInfo jobSchelueInfo) {


    }

    public void start() {

    }


    public void stop() {
        if (null != logicScheduleThreads) {
            logicScheduleThreads.shutdown();
        }
    }
}
